package com.qunar.paydata.platform.common.param;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class PageParam implements Serializable{
	
	private static final long serialVersionUID = 6297178964005032338L;
	private int pageNum; // 当前页数
	private int pageSize; // 每页记录数
	private int offset; //起始位置
	public int getPageNum() {
		return pageNum;
	}
	/**
	 * 构造分页对象，同时将分页参数放入 map
	 * @param pageNum
	 * @param pageSize
	 */
	public PageParam(int pageNum,int pageSize){
		super();
		this.pageNum = pageNum;
		this.pageSize = pageSize;
		if(this.pageNum == 0) {
			this.pageNum = 1;
		}
		this.offset = (this.pageNum-1) * this.pageSize;
	}
	
	public PageParam(String pageNumStr,String pageSizeStr) {
		this.pageNum = 1;
		this.pageSize = 20;
		try {
			this.pageNum = Integer.parseInt(pageNumStr);
			this.pageSize = Integer.parseInt(pageSizeStr);
		} catch (Exception e) {
			//不处理
		}
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getOffset() {
		return offset;
	}

	public void setOffset(int offset) {
		this.offset = offset;
	}
	
	
	
	/**
	 * 分页工具,将分页参数放入 map,并返回
	 * @param pageNum
	 * @param numPerPage
	 * @param map
	 */
	public Map<String,Object> getPageMap() {
		Map<String,Object> pageMap = new HashMap<String,Object>();
		if(pageNum == 0) {
			pageNum = 1;
		}
		pageMap.put("fromIndex", (pageNum-1) * pageSize);
		pageMap.put("numPerPage", pageSize);
		return pageMap;
	}
}
